[fix] Attribute error when trying to get bounding box from a method field value#246
[fix] Attribute error when trying to get bounding box from a method field value#246hemache wants to merge 5 commits intoopenwisp:masterfrom
Conversation
|
Hey @hemache, TravisCI finished with status TravisBuddy Request Identifier: f72e69c0-1f9e-11eb-bd2e-17a8c440c3de |
|
Hey @hemache, TravisCI finished with status TravisBuddy Request Identifier: 84aa81b0-1fc4-11eb-9dab-419bf2960c30 |
nemesifier
left a comment
There was a problem hiding this comment.
Thanks for contributing @hemache, see my question below.
| if isinstance(field, SerializerMethodField): | ||
| method = getattr(field.parent, field.method_name) | ||
| geo_value = method(instance) | ||
| feature["geometry"] = field.to_representation(instance) |
There was a problem hiding this comment.
is using instance instead of geo_value intended?
There was a problem hiding this comment.
is using
instanceinstead ofgeo_valueintended?
yes, because in this case, SerializerMethodField.to_representation receives object instance instead of the actual geometry value.
the problem was that geo_value initially stores the object instance (which doesn't provide .extent attribute), so here we're making sure to actually get the geometry value instead of the object instance.
There was a problem hiding this comment.
ok, I don't understand then what's the purpose of calling geo_value = method(instance), it seems like that line can be removed, since geo_value is not used afterwards. Isn't it?
But I am also not entirely convinced of the approach as explained above.
There was a problem hiding this comment.
since geo_value is not used afterwards. Isn't it?
yes, it's not used afterwards, but what if -later- someone else needed to use it?
I believe geo_value should have the correct/actual GEO value, not an instance of the object.
There was a problem hiding this comment.
I don't understand this. I don't want to introduce changes in a library that is used by thousands of developers lightly. Each change must be justified.
There was a problem hiding this comment.
@nemesisdesign it's justified. did you try to reproduce this bug?
focus on the type of geo_value variable. it should hold a GEO value and not something else, right?
There was a problem hiding this comment.
@nemesisdesign if you're not convinced by my solution, then please try to reproduce the bug #247 and maybe suggest a proper fix?
|
Hey @hemache, TravisCI finished with status TravisBuddy Request Identifier: c2b92120-1fe0-11eb-9dab-419bf2960c30 |
|
@nemesisdesign any idea why the CI fails because it tries to access PostgreSQL? |
@hemache Could you please try to change to |
|
Hey @hemache, TravisCI finished with status TravisBuddy Request Identifier: e2c65be0-21c0-11eb-a04c-b76cbd6ddda3 |
|
Well, that didn't exactly help. On inspection, I see: Perhaps |
b03cad0 to
a52ae4b
Compare
…er authentication for user "postgres"
ebcba18 to
0040739
Compare
|
fixed PostgreSQL issue. but now I'm getting this error (e.g. https://travis-ci.com/github/openwisp/django-rest-framework-gis/jobs/433971220) though, I can't reproduce this in my local dev env any ideas? |
|
@hemache did you already try using |
|
@nemesisdesign yep, I tried that before https://travis-ci.com/github/openwisp/django-rest-framework-gis/jobs/434284716 can we please merge this anyway and fix CI issues later? (tests are passing btw) |
f7b09ed to
0040739
Compare
|
@nemesisdesign any update on this, please? we're still using the patched version from my forked Github repo, I hope we can switch back to the official version in PyPi |
atb00ker
left a comment
There was a problem hiding this comment.
Just one comment from my end,
I'll defer the rest to @nemesisdesign
nemesifier
left a comment
There was a problem hiding this comment.
I am not sure of this change.
There's some repetition to check if the field is a SerializerMethodField.
I guess it could be resolved by changing the way SerializerMethodField and GeoFeatureModelSerializer interact.
I will look into it as soon as possible.
| if isinstance(field, SerializerMethodField): | ||
| method = getattr(field.parent, field.method_name) | ||
| geo_value = method(instance) | ||
| feature["geometry"] = field.to_representation(instance) |
There was a problem hiding this comment.
ok, I don't understand then what's the purpose of calling geo_value = method(instance), it seems like that line can be removed, since geo_value is not used afterwards. Isn't it?
But I am also not entirely convinced of the approach as explained above.
|
do you think this is ready to be merged? |
|
this need rebase |
|
Not ready to merge: #246 (comment) |
fixes #247